#!/usr/bin/env ruby

unless (ARGV[2]) then
  puts "usage :\n #{$0} wolf.sol fun3d.sol Mach"
  exit 1
end

mach = ARGV[2].to_f
re = ARGV[3].to_f
gamma = 1.4

printf("Mach %f gamma %f\n",mach,gamma)
printf("Re %f\n",re)

lines = IO.readlines(ARGV[0])

File.open(ARGV[1],'w') do |f|
  f.puts "MeshVersionFormatted 2"
  f.puts "Dimension 3"
  f.puts "SolAtVertices"
  nnode2 = lines[5].to_i
  nnode = nnode2*2
  printf("threed %d nodes\n",nnode)
  f.puts nnode
  datatype = lines[6].split(' ')
  puts datatype.join(" ")
  turbtoo = ( datatype[4] == '1' )
  if (turbtoo) then
    f.puts "4 1 2 1 1"
  else
    f.puts "3 1 2 1"
  end
  2.times do
    nnode2.times do |i|
      line = lines[i+8]
      col = line.split(/ /)
      rho = col[0].to_f
      u = col[1].to_f
      v = 0.0
      w = col[2].to_f
      p = col[3].to_f
      if (turbtoo) then
        nu = col[4].to_f
        f.printf( " %.18e %.18e %.18e %.18e %.18e %.18e\n",
                  rho, u*mach, v*mach, w*mach, p*mach*mach, nu*re )
      else
        f.printf( " %.18e %.18e %.18e %.18e %.18e\n",
                  rho, u*mach, v*mach, w*mach, p*mach*mach )
      end
      end
  end
end
